using System;
namespace OpenRay
{
	public class Color : IProceduralColor
	{
		//Immutable class
		public float Alpha {
			get {
				return Argb[0];	
			}
		}
		
		public float Red {
			get {
				return Argb[1];	
			}
		}
		
		public float Green{
			get {
				return Argb[2];	
			}
		}
		
		public float Blue {
			get {
				return Argb[3];	
			}
		}
		
		private float[] Argb = new float[4];
		
		public Color ( float r, float g, float b, float a )
		{
			Argb[1] = r;
			Argb[2] = g;
			Argb[3] = b;
			Argb[0] = a;
		}
		
		public override bool Equals (object obj)
		{
			if ( obj == null )
				return false;
			
			Color c = obj as Color;
			
			if ( c == null )
				return false;
			
			for ( int i = 0; i < 4; i++ ) {
				float f = Argb[i] - c.Argb[i];
				if ( f > 0.005 || f < -0.005 ) 
					return false;
			}
			
			return true;
		}
		
		public override int GetHashCode()
		{
			int ret = 0;
			
			for( int i = 0; i < 4; i++ ) 
			{
				ret += (int)Argb[i];	
			}
			
			return ret;
		}
		
		public override string ToString()
		{			
			return Argb[1].ToString() + ", " + Argb[2].ToString() + ", " + Argb[3].ToString() + ", " + Argb[0].ToString();
		}
		
		public static Color operator * ( Color c, float f )
		{
			return new Color( c.Argb[1] * f, c.Argb[2] * f, c.Argb[3] * f, c.Argb[0] * f );	
		}
		
		public static Color operator * ( float f, Color c )
		{
			return c * f;
		}
		
		public static Color operator * ( Color c1, Color c2 )
		{
			return new Color( c1.Argb[1] * c2.Argb[1],
			                  c1.Argb[2] * c2.Argb[2],
			                  c1.Argb[3] * c2.Argb[3],
			                  c1.Argb[0] * c2.Argb[0] );	
		}
		
		public static Color operator + ( Color c1, Color c2 )
		{
			return new Color( c1.Argb[1] + c2.Argb[1],
			                  c1.Argb[2] + c2.Argb[2],
			                  c1.Argb[3] + c2.Argb[3],
			                  c1.Argb[0] + c2.Argb[0] );	
		}
		
		public float[] ToArgb()
		{
			return (float[])Argb.Clone();	
		}
		
		public Color Evaluate(Point ModelHit)
		{
			return this;	
		}
	}
}

